package org.bioversityinternational.mgbms.model.dao;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.hibernate.Query;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.bioversityinternational.mgbms.model.dao.base.BaseDao;
import org.bioversityinternational.mgbms.model.domain.NewCentre;

@Component
public class NewCentreDao extends BaseDao<NewCentre, Integer>
{
	private static final Logger LOG = Logger.getLogger(NewCentreDao.class);
	
	public NewCentreDao() {
		super(NewCentre.class);		
        LOG.debug("NewCentreDao constructed");
	}
	
//	@SuppressWarnings("unchecked")
//	@Transactional(propagation=Propagation.SUPPORTS)
//	public Map<Integer, String> listValidNewCentres() {
//		String sQuery = "select id,acronym from " + type.getName() + " where name is not null and length(name) > 0 and acronym is not null and length(acronym) > 0 order by acronym";
//		Query query = getSession().createQuery(sQuery);
//		
//		Map<Integer, String> result = new LinkedHashMap<Integer, String>();
//		List<Object[]> records = query.list();
//		for (Object[] record : records)
//			result.put((Integer) record[0], (String) record[1] );
//		
//        LOG.debug("hql: " + sQuery + " -> " + result.size() + " results");
//		return result;
//	}
	
//	@SuppressWarnings("unchecked")
//	@Transactional(propagation=Propagation.SUPPORTS)
//	public NewCentre getLatestNewCentreForContact(Integer contactId) {
//		String sQuery = "from " + ContactNewCentre.class.getName() + " where contact.id=:P order by id";	/* id doit devenir startDate */
//		Query query = getSession().createQuery(sQuery);
//		query.setParameter("P", contactId);
//		query.setMaxResults(1);
//		
//		ContactNewCentre contactNewCentre = (ContactNewCentre) query.uniqueResult();
//		
//        LOG.debug("hql: " + sQuery + " -> " + (contactNewCentre == null ? 0 : 1) + " result");
//		return contactNewCentre == null ? null : contactNewCentre.getNewCentre();
//	}

	@Override
	public Integer getIdFromString(String sIdAsString) {
		return Integer.parseInt(sIdAsString);
	}
		
}

